package com.webdesign.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.webdesign.dto.MyPage;
import com.webdesign.dto.UserDTO;
import com.webdesign.entity.TbUser;
import com.webdesign.service.ITbUserService;

@Controller("ResetPasswordAction")
@Scope("prototype")
public class ResetPasswordAction extends ActionSupport{
private ITbUserService iTbUserService;
	
	private String usersid;
	
	private Boolean flag;
	
	private String numpage;
	
	private MyPage page;
	
	private List<TbUser> users;
	
	/*
	 * 点击重置密码，跳转到showUsers,根据页码为第一页返回第一页的学生信息
	 */
	public String showUsers() {  
		Map<String,Object> session = ActionContext.getContext().getSession();
		String termid = (String)session.get("termid");
		String teacherId = (String)session.get("userid");
		users = iTbUserService.showUsers(termid,teacherId);
		
		String pageNumber = CookieAction.getCookie("pagenumber");
		if(page == null){
			page = new MyPage();
			page.setNumber(1);
		}
		if(pageNumber != null && pageNumber!=""){
			page.setNumber(Integer.parseInt(pageNumber));
		}
		if(numpage != null){
			page.setNumber(Long.parseLong(numpage));
		}
		
		page.setTotalElements(users.size());
		users = users.subList((int)(page.getStart()), (int)(page.getEnd()));
	    return SUCCESS;  
	}  
	
	
	/*
	 * 重置密码
	 */
	public String resetPassword(){
		Map<String,Object> session = ActionContext.getContext().getSession();
		String termid = (String)session.get("termid");
		String[] userid = usersid.split(",");
		
		flag = iTbUserService.resetPassword(userid);
		
		return "success";
	}


	public ITbUserService getiTbUserService() {
		return iTbUserService;
	}


	@Resource(name="TbUserService")
	public void setiTbUserService(ITbUserService iTbUserService) {
		this.iTbUserService = iTbUserService;
	}

	public String getUsersid() {
		return usersid;
	}

	public void setUsersid(String usersid) {
		this.usersid = usersid;
	}

	public Boolean getFlag() {
		return flag;
	}

	public void setFlag(Boolean flag) {
		this.flag = flag;
	}


	public String getNumpage() {
		return numpage;
	}


	public void setNumpage(String numpage) {
		this.numpage = numpage;
	}


	public MyPage getPage() {
		return page;
	}


	public void setPage(MyPage page) {
		this.page = page;
	}


	public List<TbUser> getUsers() {
		return users;
	}


	public void setUsers(List<TbUser> users) {
		this.users = users;
	}


	


}
